using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gko.Utils.Interfaces;

namespace Gko.Utils
{
	internal class BindablePropertyDescription<TBindable, TProperty> : IEquatable<BindablePropertyDescription<TBindable, TProperty>> where TBindable : IBindable
	{
		private readonly TBindable bindable;
		private readonly string propertyName;

		public BindablePropertyDescription(TBindable bindable, string propertyName)
		{
			if (ReferenceEquals(bindable, null)) {
				throw new ArgumentNullException("bindable");
			}
			if (propertyName == null) {
				throw new ArgumentNullException("propertyName");
			}
			this.bindable = bindable;
			this.propertyName = propertyName;
		}

		public bool Equals(BindablePropertyDescription<TBindable, TProperty> other)
		{
			if (ReferenceEquals(null, other)) {
				return false;
			}
			if (ReferenceEquals(this, other)) {
				return true;
			}
			return other.bindable.Equals(this.bindable) && other.propertyName.Equals(this.propertyName);
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj)) {
				return false;
			}
			if (ReferenceEquals(this, obj)) {
				return true;
			}
			if (obj.GetType() != typeof(BindablePropertyDescription<TBindable, TProperty>)) {
				return false;
			}
			return this.Equals((BindablePropertyDescription<TBindable, TProperty>)obj);
		}

		public override int GetHashCode()
		{
			unchecked {
				return (this.bindable.GetHashCode() * 397) ^ (this.propertyName != null ? this.propertyName.GetHashCode() : 0);
			}
		}
	}
}